package com.hdax.dm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hdax.dm.common.utils.CommonResponse;
import com.hdax.dm.common.utils.ResponseUtil;
import com.hdax.dm.dtos.scheduler.ChooseSeatScheduleDto;
import com.hdax.dm.entity.scheduler.DmSchedulerSeat;
import com.hdax.dm.entity.scheduler.DmSchedulerSeatPrice;
import com.hdax.dm.mappers.SchedulerSeatMapper;
import com.hdax.dm.mapstructs.SeatInfoDtoMapper;
import com.hdax.dm.mapstructs.SeatPriceDtoMapper;
import com.hdax.dm.service.ChooseSeatService;
import com.hdax.dm.service.SchedulerSeatPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChooseSeatServiceImpl implements ChooseSeatService {

    @Autowired
    private SchedulerSeatPriceService priceService;
    @Autowired
    private SeatPriceDtoMapper seatPriceDtoMapper;
    @Autowired
    private SchedulerSeatMapper seatMapper;
    @Autowired
    private SeatInfoDtoMapper seatInfoDtoMapper;
    @Override
    public CommonResponse<ChooseSeatScheduleDto> getSchedule(Long scheduleId, Long cinemaId) {

        ChooseSeatScheduleDto dto = new ChooseSeatScheduleDto();
        dto.setScheduleId(scheduleId);
        dto.setCinemaId(cinemaId);



        //调用数据访问层查询本场演出一共有几类票价
        List<DmSchedulerSeatPrice> seatPrices = priceService.list(new QueryWrapper<DmSchedulerSeatPrice>()
                .eq("scheduleId", scheduleId));
        List<ChooseSeatScheduleDto.SeatPrice> targetList = seatPriceDtoMapper.toTargetList(seatPrices);
        dto.setSeatPriceList(targetList);
        //查询所有可以出售的座位
        List<DmSchedulerSeat> dmSchedulerSeats = seatMapper.seatList(scheduleId);
        List<ChooseSeatScheduleDto.SeatInfo> targetList1 = seatInfoDtoMapper.toTargetList(dmSchedulerSeats);
        dto.setSeatInfoList(targetList1);
        return ResponseUtil.returnSuccess(dto);
    }
}
